<template>
  <div>
    <el-tabs v-model="search.status" @tab-click="tabClick">
        <el-tab-pane
          :label="item.name + '(' + item.num + ')'" 
          v-for="item in produceStatic"
          :key="item.id"
        ></el-tab-pane>
      </el-tabs>
    <div class="nav">
      <div class="right">
        <el-form :inline="true"  ref="searchForm" :model="search" class="demo-form-inline">
          <el-form-item label="门店名称" props="shopName">
            <el-input
              v-model="search.shopName"
              placeholder="门店名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="门店编码">
            <el-input v-model="search.shopId" placeholder="门店编码"></el-input>
          </el-form-item>
          <el-form-item label="商品码">
            <el-input
              v-model="search.produceId"
              placeholder="商品码/商品编码"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="left">
        <el-link type="primary" @click="resetForm('searchForm')">重置筛选条件</el-link>
        <el-button
          type="primary"
          @click="submitForm('searchForm')"
          icon="el-icon-search"
          >查询</el-button
        >
      </div>
    </div>
    <div class="btn">
      <el-button type="primary" icon="el-icon-upload2">批量上架</el-button>
      <el-button type="primary" icon="el-icon-download">批量下架</el-button>
      <el-button type="danger" icon="el-icon-delete">批量删除</el-button>
      <el-button type="info" icon="el-icon-setting">设置门店库存</el-button>
    </div>
    <!-- 列表数据 -->
    <el-table :data="produceList" border style="width: 100%">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="商品图片">
        <template slot-scope="scope">
          <img :src="scope.row.gallery" style="width: 50px; height: 50px" />
        </template>
      </el-table-column>
      <el-table-column prop="cateName" label="商品名称"> </el-table-column>
      <el-table-column prop="price" label="价格"> </el-table-column>
      <el-table-column prop="stock" label="库存"> </el-table-column>
      <el-table-column prop="stock" label="月售（份）"> </el-table-column>
      <el-table-column prop="sku" label="条形码（SKU)"> </el-table-column>
      <el-table-column prop="produceId" label="商品编码"> </el-table-column>
      <el-table-column prop="shopName" label="门店名称"> </el-table-column>
      <el-table-column prop="shopId" label="门店编码"> </el-table-column>
      <el-table-column label="是否上架">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.online"> </el-switch>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="pagination.current"
      :page-size="pagination.size"
      :page-sizes="[5, 10, 20]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagination.total"
    >
    </el-pagination>
  </div>
</template>
<script>
import { GetProduceList,GetProduceStatic } from "@/api/produce";
export default {
  data() {
    return {
      produceList: [],
      pagination: {}, //分页数据
      search: {status: "", orderNum: ""},
      produceStatic:[]
    };
  },
  created() {
    this.getProduceList();
    this.getProduceStatic()
  },
  methods: {
    tabClick(tab) {
      //   console.log(tab, event);
      this.search.status = tab.name;
      //   console.log(tab);
      this.getProduceList();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
            this.getProduceList();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.getOrderList();
    },
    // 处理size变化
    handleSizeChange(val) {
      // 当每页多少条发生变化时候，重新更新搜索条件size
      // 重新获取员工列表
      console.log(`每页 ${val} 条`);
      this.search.size = val;
      this.getProduceList();
    },
    // 处理current变化
    handleCurrentChange(val) {
      // 当当前页发生变化时候更新 搜索条件的当前页
      // 获取数据
      this.search.current = val;
      this.getProduceList();
    },
    getProduceStatic(){
        GetProduceStatic()
        .then(res=>{
            console.log(res.data.list)
            this.produceStatic=res.data.list;
        })
    },
    getProduceList() {
      
      GetProduceList(this.search).then((res) => {
        console.log(res.data, "产品详情");
        this.produceList = res.data.data;
        this.pagination = res.data.pagnation;
        this.pagination.current = this.pagnation.current * 1;
        this.pagination.size = this.pagnation.size * 1;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.nav {
  display: flex;
  justify-content: space-between;
  margin-top:10px;
}
.btn {
  margin: 10px 0;
  padding: 0 10px;
}
</style>
